import axios from 'axios'
import {defineStore} from "pinia";
import {ref} from "vue";
export const userImg = defineStore('Img', () => {
    const img_list = ref([]) //单独上传图片集合
    const space_list = ref([
        {
            id: 1,
            name: "张三",
            message: "今天天气真好",
            imglist: ["/cxy.jpg"],
            time: "2022-07-06 12:00:00",
            like: false,
            children: []
        },
        {
            id: 2,
            name: "李四",
            message: "今天天气晴转多云",
            imglist: [],
            time: "2022-07-08 12:00:00",
            like: false,
            children: []
        },
        {
            id: 3,
            name: "王五",
            message: "今天天气晴转多云",
            imglist: ["/avater.jpeg"],
            time: "2022-07-06 12:00:00",
            like: false,
            children: []
        },
    ]) //上传的说说集合
    const plarr = ref([]) //评论集合
    const pushimg = (img) => {
        img_list.value.push(img)
        // 将数据传递到后端
        axios.post('/add', img_list.value).then(res => {
            console.log(res)
        })
    }
    const pushspace = (space) => {
        space_list.value.push(space)
        {}
        console.log(space)
    }
    const like = (index) => {
        space_list.value[index].like = !space_list.value[index].like
    }

    const delspace = (index) => {
        space_list.value.splice(index, 1)
    }
    const deluseimg = (index) => {
        img_list.value.splice(index, 1)
    }
    const pladd = (item) => {
        plarr.value.push(item)
        console.log(plarr.value)
    }
    return {
        img_list,
        pushimg,
        space_list,
        pushspace,
        like,
        deluseimg,
        pladd,
        plarr,
        delspace
    }
})